import instance from '../axios_config'
import { ElMessage } from 'element-plus'
import get_menus from './get_menus'
interface UserInfo1 {
  username: ''
  password: ''
}

const get_token = async (data: UserInfo1) => {
  try {
    const res = await instance.post('token/', data)
    sessionStorage.setItem('token', 'Bearer  ' + res.data.access)
    await get_menus()
    return res.data.access
  } catch {
    ElMessage.error('你输入的用户名或密码有误！')
  }
}

export default get_token
